#!/usr/bin/python3

from tkinter import *

class Application(Frame):
    """Build the basic window frame template"""

    def __init__(self, master):
        super(Application, self).__init__(master)
        self.grid()
        
        self.create_widgets()

    def create_widgets(self):
        self.label1 = Label(self, text="Please enter some text in lower case")
        self.label1.grid(row=0,column=0,sticky=W)
        #label1方法的使用以及grid定位
        self.text1=Text(self,width=20,height=10)
        #Text方法实现多行文字的输入,使用,width=20,height=10对多行输入框设置
        self.text1.grid(row=1,column=0)
        self.text1.focus_set()#光标的定位
       
        self.button1 = Button(self, text='convert text', command=self.convert)
        self.button1.grid(row=2,column=0)
        self.button2 = Button(self, text='clear result', command=self.clear)
        self.button2.grid(row=2,column=1)
        
    def convert(self):
        """"retrieve the text and convert to upper case"""
        varText=self.text1.get("1.0",END)#多行文本输入Text的定位方式
        #self.text1.get("1.0",END)--("1.0",END)表示就是从首位开始
        varReplaced=varText.upper()#字符串的大写转换
        self.text1.delete("1.0",END)#删掉从开始位置到最后的内容
        self.text1.insert(END,varReplaced)#再将转换的内容插入进去
    def clear(self):
        """clear the entry form"""
        self.text1.delete("1.0",END)#删掉所有内容
        self.text1.focus_set()#定位光标
        
        
root = Tk()
root.title('Test and Entry widget')
root.geometry('300x250')
app = Application(root)
app.mainloop()
